package sifeap.dal.ejb.soportes;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import sifeap.dal.ejb.AbstractFacade;
import sifeap.entities.soportes.Soporte;
import sifeap.exception.SifeapException;

/**
 * Session Bean implementation class EventoBL
 */
@Stateless(name="SoporteDAL")
public class SoporteDAL extends AbstractFacade<Soporte> implements SoporteDALLocal {

	@PersistenceContext(unitName = "sifeapPU")
	private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public SoporteDAL() {
    	super(Soporte.class);
    }

	@Override
	protected EntityManager getEntityManager() {
		return em;
	}

	@Override
	public List<Soporte> buscarSoportesSolicitudCredito(long idSolicitudCredito) throws SifeapException {
		List<Soporte> listaSoportes = null;
		try {
			final javax.persistence.Query query = em.createNamedQuery("soportesSolicitudCredito", Soporte.class);
			query.setParameter(1, idSolicitudCredito);
			query.setParameter(2, idSolicitudCredito);
			query.setHint("javax.persistence.cache.storeMode", "REFRESH");
			listaSoportes = query.getResultList();
		} catch (Exception e) {
			throw new SifeapException(e);
		}
		return listaSoportes;
	}
	
	@Override
	public List<Soporte> buscarSoportesSolicitudAuxilio(long idSolicitudAuxilio) throws SifeapException {
		List<Soporte> listaSoportes = null;
		try {
			final javax.persistence.Query query = em.createNamedQuery("soportesSolicitudAuxilio", Soporte.class);
			query.setParameter(1, idSolicitudAuxilio);
			query.setHint("javax.persistence.cache.storeMode", "REFRESH");
			listaSoportes = query.getResultList();
		} catch (Exception e) {
			throw new SifeapException(e);
		}
		return listaSoportes;
	}
}
